﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using System.Data;
using ZX.CRM.Bussiness;
using ZX.EHR.Library;
using ZX.BLL;
using ZX.Web.UI.Controls.ControlBind;

namespace ZX.WebApp.Crm.Report
{
    public partial class RptPayDetail : BasePage
    {      
        BCrmReport BReport = new BCrmReport();
        BDatDepartment bllDetail = new BDatDepartment();
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
              if (!IsPostBack)
              {
                //分公司
                IList<DatDepartment> ListDetailDeptName = bllDetail.GetAllDatDepartmentByDeptType();
                DropDownListControl.DropDataSourceBind(this.dpDeptName, ListDetailDeptName, "DeptName", "DeptID");
              }            
             
              bind();           
           
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }


        private void bind()
        {
            try
            {
                string strDeptName = this.dpDeptName.SelectedValue;
                string strYear = this.txtYear.Text.Trim();
                string strMonth = this.txtMonth.Text.Trim();
                if (strDeptName == "") return;
                if (strYear == "" || strMonth == "") return;
                DateTime start = Convert.ToDateTime(strYear + "-" + strMonth + "-1");
                DateTime end = start.AddMonths(1).AddDays(-1);                
                DataSet myDataSet = new DataSet();
                DataTable DtPayMoney = BReport.ReturnRptPayDetailReprot(strDeptName, "0", start.ToString(), end.ToString());
                if (myDataSet != null)
                {
                    myDataSet.Tables.Add(DtPayMoney.Copy());
                    myDataSet.DataSetName = "DsPayDetail";
                    myDataSet.Tables[0].TableName = "PayDetail";
                    DataTable datetable = new DataTable("DTDate");
                    myDataSet.Tables.Add(datetable);
                    datetable.Columns.Add("BeginDate", typeof(string));
                    datetable.Columns.Add("EndDate", typeof(string));
                    datetable.Columns.Add("CourseName", typeof(string));
                    datetable.Rows.Add(new object[] { "", "", BReport.ReturnDeptNameByDeptid(strDeptName) + start.ToString("yyyy-MM") });
                    ZX.CRM.Report.CrmReport.PayDetail crm = new ZX.CRM.Report.CrmReport.PayDetail();
                    crm.DataSource = myDataSet;
                    int coutn = myDataSet.Tables[0].Rows.Count;
                    RV.Report = crm;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 查询按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {                        
                bind();    
        }
    }
}